<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"  %>
<script type="text/javascript">
$.unblockUI();
$(document).ready(function() {
	  $('#typeTaskFormDiv').hide();
	  $('#statusTaskFormDiv').hide();  
});

$("#taskForm").validate({
	submitHandler: function(form) {
		var idtask = $('#taskForm_task_id').val();
		if(idtask != '' && idtask != 0) {
			if(confirmOperation('modify')) {
				$.post('./task/saveTask', $('#taskForm').serialize(), function(resultadoHTML) {
					$('#content').html(resultadoHTML);			
				});
    		}	
		} else {
			$.post('./task/saveTask', $('#taskForm').serialize(), function(resultadoHTML) {
				$('#content').html(resultadoHTML);			
			});
		}
	}
});

$("#typeTaskForm").validate({
	submitHandler: function(form) {
		$.post('./task/saveTypeTask', $('#typeTaskForm').serialize(), function(resultadoHTML) {
			$('#content').html(resultadoHTML);
		});
	}
});


$("#typeTaskForm").validate({
	submitHandler: function(form) {
		$.post('./task/saveStatusTask', $('#statusTaskForm').serialize(), function(resultadoHTML) {
			$('#content').html(resultadoHTML);
		});
	}
});


$('#startDate').datepicker();
$('#finishDate').datepicker();


function showNewTypeTaskForm() {
   $('#statusTaskFormDiv').hide();
	 $('#typeTaskFormDiv').show();
};

function showNewStatusTaskForm() {
	 $('#typeTaskFormDiv').hide();
	 $('#statusTaskFormDiv').show();
};

</script>
<h4>
	New Task:
</h4>
<br>
<s:form id="taskForm" action="saveTask" >
	<s:hidden name="task.id" />
	<s:hidden name="idProject" id="idProject"/>
	<s:textfield cssClass="required" name="task.title" label="Title" id="title"/>
	<s:textarea cssClass="required" name="task.description" label="Description" cols="15" rows="3"/>
	<s:textfield cssClass="required" name="task.hours" label="Estimated Hours" id="hours"/>
	<s:select name="task.taskStatus.id" list="taskStatus" listValue="name" listKey="id" label="Task Status"></s:select>
	<s:select name="task.taskType.id" list="taskTypes" listValue="name" listKey="id" label="Task Type"></s:select>
	<s:textfield cssClass="required" name="task.period.startDate" label="Start Date" id="startDate"/>
	<s:textfield cssClass="required" name="task.period.endDate" label="Finish Date" id="finishDate"/>
	<s:if test="task.id != null && task.id != 0">
		<s:submit cssClass="btn btn-success" id="botSave" align="left" value="Modify"/>
	</s:if>
	<s:else>
		<s:submit cssClass="btn btn-success" id="botSave" align="left" value="Save"/>
	</s:else>
</s:form>
<br/><br/><br/>
<a class="btn btn-mini" href="#" onclick="showNewTypeTaskForm()">New Type Task</a>
<br/><br/>
<a class="btn btn-mini" href="#" onclick="showNewStatusTaskForm()">New Status Task</a>
<br/><br/><br/>

<div id="typeTaskFormDiv">
<s:form id="typeTaskForm" action="saveTypeTask" >
	<s:hidden name="taskType.id" />
	<s:textfield cssClass="required" name="taskType.name" label="Type Name" id="nameType"/>
	<s:submit id="botSaveTypeTask" align="left" value="ADD"/>
</s:form>
<br/>
</div>

<div id="statusTaskFormDiv">
<s:form id="statusTaskForm" action="saveStatusTask" >
	<s:hidden name="taskStatus2.id" />
	<s:textfield cssClass="required" name="taskStatus2.name" label="Status Name" id="nameStatus"/>
	<s:submit id="botSaveStatusTask" align="left" value="ADD"/>
</s:form>
</div>